//
//  LCZCacheSaveTool.m
//  PersonalNews
//
//  Created by Golibyo on 15/12/7.
//  Copyright © 2015年 changshuhua. All rights reserved.
//

#import "LCZCacheSaveTool.h"

@implementation LCZCacheSaveTool

+ (NSMutableArray *)cacheSaveGet:(NSString *)plistName {
    NSString *sandBoxPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
    NSString *docPath = [sandBoxPath stringByAppendingPathComponent:plistName];
    NSLog(@"%@", docPath);
    //    反归档
    NSMutableArray *array = [NSKeyedUnarchiver unarchiveObjectWithFile:docPath];
    return array;
}
//缓存的存储
+ (void)cacheSave:(NSMutableArray *)array :(NSString *)plistName {
    NSString *sandBoxpath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
    NSString *docPath = [sandBoxpath stringByAppendingPathComponent:plistName];
    [NSKeyedArchiver archiveRootObject:array toFile:docPath];
    NSLog(@"%@", docPath);
}
//缓存的删除
+ (void)cacheSaveRemoveAll:(NSString *)plistName {
    NSString *sandBoxpath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
    NSString *docPath = [sandBoxpath stringByAppendingPathComponent:plistName];
    //    反归档
    NSMutableArray *array = [NSKeyedUnarchiver unarchiveObjectWithFile:docPath];
    array = nil;
    [NSKeyedArchiver archiveRootObject:array toFile:docPath];
}

+ (void)isHaveFieldCalendar:(NSString *)fieldName {
    //    1.找沙盒路径
    NSString *sandBoxPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
    //    2.拼接电影的文件夹名
    NSString *movieFile = [sandBoxPath stringByAppendingPathComponent:fieldName];
    //    创建一个文件管理者
    NSLog(@"%@", movieFile);
    NSFileManager *manager = [NSFileManager defaultManager];
    //    通过管理者调用方法,根据路径判断文件夹是否存在
    if (![manager fileExistsAtPath:movieFile]) {
        [manager createDirectoryAtPath:movieFile withIntermediateDirectories:YES attributes:nil error:nil];
    }

}

+ (void)calendarHistroySave:(NSDictionary *)dic :(NSString *)plistName {
    BOOL ishave = NO;
    NSString *sandBoxPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
    NSString *docPath = [sandBoxPath stringByAppendingPathComponent:plistName];
    NSLog(@"%@", docPath);
    //    反归档
    NSMutableArray *array = [NSKeyedUnarchiver unarchiveObjectWithFile:docPath];
    for (NSDictionary *temp in array) {
        if ([temp[@"myTitle"]isEqualToString:dic[@"myTitle"]]) {
            ishave = YES;
            break;
        }
    }
    if (!ishave) {
        if (array == nil) {
            array = [NSMutableArray array];
        }
        [array addObject:dic];
        [NSKeyedArchiver archiveRootObject:array toFile:docPath];
        
    }
}





@end
